﻿using Microsoft.AspNetCore.Authorization;
using Simple.Services.System.Article;
using Simple.Services.System.Article.Model;
using Simple.Services.System.Market;
using Simple.Services.System.Market.Models;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 商城相关
    /// </summary>
    [Route("api/Market/[action]")]
    [ApiController]
    [Authorize]
    public class MarketController : ControllerBase
    {
        private readonly MarketService _marketService;
        public MarketController(MarketService marketService)
        {
            _marketService = marketService;
        }

        /// <summary>
        /// 查询商品分类详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetCategorieyInfo([FromQuery] Guid? Id)
        {
            var data = await _marketService.GetCommodityCategorieyAsync(Id);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 商品分类列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetCategories()
        {
            var data = await _marketService.GetCommodityCategories();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 添加商品分类
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> AddCategoriey([FromForm] CommodityCategoryModel model)
        {
            await _marketService.AddCommodityCategorieyAsync(model);
            return AppResult.Status200OK("新增成功");
        }

        /// <summary>
        /// 修改商品分类
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> EditCategoriey([FromForm] CommodityCategoryModel model)
        {
            await _marketService.UpdateCommodityCategorieyAsync(model);
            return AppResult.Status200OK("修改成功");
        }

        /// <summary>
        /// 删除商品分类
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> DeleteCategorieies([FromForm] List<Guid?> ids)
        {
            await _marketService.DeleteCommodityCategorieyAsync(ids);
            return AppResult.Status200OK("删除成功");
        }

        /// <summary>
        /// 查询商品详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetInfo([FromQuery] Guid? Id)
        {
            var data = await _marketService.GetCommodityAsync(Id);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 商品列表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> GetInfoPage([FromQuery] CommodityPageQueryModel model)
        {
            var data = await _marketService.GetCommodityPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 添加商品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Add([FromForm] CommodityCreateOrUpdateModel model)
        {
            await _marketService.AddCommodityAsync(model);
            return AppResult.Status200OK("新增成功");
        }

        /// <summary>
        /// 修改商品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Edit([FromForm] CommodityCreateOrUpdateModel model)
        {
            await _marketService.UpdateCommodityAsync(model);
            return AppResult.Status200OK("修改成功");
        }

        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete([FromForm] List<Guid?> ids)
        {
            await _marketService.DeleteCommodityAsync(ids);
            return AppResult.Status200OK("删除成功");
        }

    }
}
